package org.jeecg.modules.demo.gmslopedata.controller;



import org.jeecg.modules.demo.gmIndexAdjustment.entity.GmIndexAdjustment;
import org.jeecg.modules.demo.gmhazardparameters.entity.GmHazardParameters;
import org.jeecg.modules.demo.gmslopedata.entity.GmSlopeData;
import org.jeecg.modules.demo.rockslopestablesetting.entity.RockSlopeStableSetting;
import org.jeecg.modules.demo.sloperiskevaluationsetting.entity.SlopeRiskEvaluationSetting;
import org.jeecg.modules.demo.slopestablesetting.entity.SlopeStableSetting;
import org.jeecg.modules.demo.soilrockslopesetting.entity.SoilRockSlopeSetting;

import java.util.Objects;

/**
 * 功能描述
 *
 * @program: geology-monitor
 * @description:
 * @author: wwq
 * @create: 2025-06-22 11:00
 **/
public class Utils {


    /**
     * 计算土质边坡的 Y 值
     *
     * @param setting
     * @param gmSlopeData
     * @return
     */
    public static double calculateSlopeY(SlopeStableSetting setting, GmSlopeData gmSlopeData) {
        double y = 0.00;

        // 切坡高度
        y += setting.getCutSlopeHeightWeight() * getCutSlopeHeightValue(setting, gmSlopeData.getCutSlopeHeight());
//        System.out.println("ya= " + y);

        // 切坡坡度
        y += setting.getCutSlopeGradientWeight() * getCutSlopeGradientValue(setting, gmSlopeData.getCutSlopeGradient());
//        System.out.println("yb= " + y);


        // 切坡坡形
        y += setting.getCutSlopeShapeWeight() * getCutSlopeShapeValue(setting, gmSlopeData.getCutSlopeShape());
//        System.out.println("yc= " + y);


        // 自然斜坡坡度
        y += setting.getNaturalSlopeGradientWeight() * getNaturalSlopeGradientValue(setting, gmSlopeData.getNaturalSlopeGradient());
//        System.out.println("yd= " + y);

        // 土层松散程度
        y += setting.getSoilLoosenessWeight() * getSoilLoosenessValue(setting, gmSlopeData.getSoilLooseness());
//        System.out.println("ye= " + y);

        // 土体类型
        y += setting.getOverlyingSoilTypeWeight() * getOverlyingSoilTypeValue(setting, gmSlopeData.getOverlyingSoilType());
//        System.out.println("yf= " + y);

        //岩组类型
        y += setting.getRockTypeWeight() * calculateRockY(setting, gmSlopeData.getRockType());
//        System.out.println("yg= " + y);

        // 植被覆盖率
//        y += setting.getVegetationCoverageWeight() * getVegetationCoverageValue(setting, gmSlopeData.getVegetationCoverage());


        // 已有治理措施
//        y += setting.getGovernanceMeasuresWeight() * getGovernanceMeasuresValue(setting, gmSlopeData.getGovernanceMeasures());


        return y;
    }

    /**
     * 计算岩质边坡的 Y 值
     *
     * @param setting
     * @param gmSlopeData
     * @return
     */
    public static double calculateRockY(RockSlopeStableSetting setting, GmSlopeData gmSlopeData) {
        double y = 0.00;
        // 切坡高度
        y += setting.getCutSlopeHeightWeight() * getCutSlopeHeightValue(setting, gmSlopeData.getCutSlopeHeight());
        // 切坡坡度
        y += setting.getCutSlopeGradientWeight() * getCutSlopeGradientValue(setting, gmSlopeData.getCutSlopeGradient());
        //切坡坡形
        y += setting.getCutSlopeShapeWeight() * getCutSlopeShapeValue(setting, gmSlopeData.getCutSlopeShape());
        // 自然斜坡坡度
        y += setting.getNaturalSlopeGradientWeight() * getNaturalSlopeGradientValue(setting, gmSlopeData.getNaturalSlopeGradient());
        //岩体特征
        y += setting.getRockCharacteristicsWeight() * getRockCharacteristicsValue(setting, gmSlopeData.getRockCharacteristics());
        //裂隙发育程度
        y += setting.getFractureDevelopmentWeight() * getFractureDevelopmentValue(setting, gmSlopeData.getFractureDevelopmentDegree());
        //岩组类型
        y += setting.getRockTypeWeight() * calculateRockY(setting, gmSlopeData.getRockType());
        // 植被覆盖率
//        y += setting.getVegetationCoverageWeight() * getVegetationCoverageValue(setting, gmSlopeData.getVegetationCoverage());

        // 已有治理措施
//        y += setting.getGovernanceMeasuresWeight() * getGovernanceMeasuresValue(setting, gmSlopeData.getGovernanceMeasures());

        return y;

    }


    /**
     * 计算混合边坡的 Y 值
     *
     * @param setting
     * @param gmSlopeData
     * @return
     */
    public static double calculateSoilRockY(SoilRockSlopeSetting setting, GmSlopeData gmSlopeData) {

        double y = 0.0;
        // 切坡高度
        y += setting.getCutSlopeHeightWeight() * getCutSlopeHeightValue(setting, gmSlopeData.getCutSlopeHeight());
//        System.out.println("ya= " + y);

        // 切坡坡度
        y += setting.getCutSlopeGradientWeight() * getCutSlopeGradientValue(setting, gmSlopeData.getCutSlopeGradient());
//        System.out.println("yb= " + y);


        // 切坡坡形
        y += setting.getCutSlopeShapeWeight() * getCutSlopeShapeValue(setting, gmSlopeData.getCutSlopeShape());
//        System.out.println("yc= " + y);

        // 自然斜坡坡度
        y += setting.getNaturalSlopeGradientWeight() * getNaturalSlopeGradientValue(setting, gmSlopeData.getNaturalSlopeGradient());
//        System.out.println("yd= " + y);
        //上覆土层松散程度upperSoilLoosenessWeight
        y += setting.getUpperSoilLoosenessWeight() * getSoilLoosenessValue(setting, gmSlopeData.getSoilLooseness());
//        System.out.println("ye= " + y);
        //上覆土体类型upperSoilTypeWeight
        y += setting.getUpperSoilTypeWeight() * getOverlyingSoilTypeValue(setting, gmSlopeData.getOverlyingSoilType());
//        System.out.println("yf= " + y);
//		 下部岩体特征underCharacteristicsWeight
        y += setting.getUnderCharacteristicsWeight() * getRockCharacteristicsValue(setting, gmSlopeData.getRockCharacteristics());
//        System.out.println("yg= " + y);
        // 下部岩体裂隙发育程度underRockFractureWeight
        y += setting.getUnderRockFractureWeight() * getFractureDevelopmentValue(setting, gmSlopeData.getFractureDevelopmentDegree());
//        System.out.println("yh= " + y);
        //岩组类型
        y += setting.getRockTypeWeight()* calculateRockY(setting, gmSlopeData.getRockType());
//        System.out.println("yi= " + y);

        // 植被覆盖率
//        y += setting.getVegetationCoverageWeight() * getVegetationCoverageValue(setting, gmSlopeData.getVegetationCoverage());

        // 已有治理措施
//        y += setting.getGovernanceMeasuresWeight() * getGovernanceMeasuresValue(setting, gmSlopeData.getGovernanceMeasures());
        return y;
    }



    /**
     * 计危险 Y 值
     *
     * @param riskSetting
     * @param gmSlopeData
     * @return
     */

    public static double calculateDangerY(SlopeRiskEvaluationSetting riskSetting, GmSlopeData gmSlopeData) {
        double y = 0.0;
        // 切坡墙距（A）slopeWallDistanceWeight
        y += riskSetting.getSlopeWallDistanceWeight() * getWallDistanceValue(riskSetting, gmSlopeData.getSlopeWallDistance());
        //		 切坡时间
        y += riskSetting.getCutSlopeTimeWeight() * getCutSlopeTimeValue(riskSetting, gmSlopeData.getCutSlopeTime());
        // 切坡宽度（B）
        y += riskSetting.getCutSlopeWidthWeight() * getCutSlopeWidthValue(riskSetting, gmSlopeData.getCutSlopeWidth());
        // 威胁人口（C） 4
        y += riskSetting.getThreatPopulationWeight() * getThreatPopulationValue(riskSetting, gmSlopeData.getThreatPopulation());
        // 威胁房屋结构 4
        y += riskSetting.getThreatHouseWeight() * getThreatHouseValue(riskSetting, gmSlopeData.getThreatHouse());
        return y;

    }




//    /**
//     * 核心方法：计算4种降雨工况的危险性等级，并写入 GmSlopeData 实体对应字段
//     * @param wi 边坡稳定性指数（动态传入）
//     * @param gmSlopeData 需要赋值的实体对象
//     */
//    public static void calculateAndSetHazardLevels(double wi, double y4,GmSlopeData gmSlopeData, GmHazardParameters hazardParameters) {
//        // 遍历 4 种降雨工况（L1~L4 对应索引 0~3）
//        for (int i = 0; i < LJ_VALUES.length; i++) {
//            double lj = LJ_VALUES[i]; // 当前工况的雨量代表值（35/75/175/250）
//
//            // 公式计算：H_ij = (W_i / W_max) * ln(L_j / L_max + 2)
//            double hij = (wi / W_MAX) * Math.log(lj / L_MAX + 2);
//            double hij1 =hij*y4;
//
//
//            // 判定危险等级
//            String level = getRiskLevel(hij);
//            String level1 = getRiskLevel1(hij1);
//
//            // 根据工况索引，调用实体类 setter 赋值对应字段
//            switch (i) {
//                case 0: // L1（大雨）→ slopeHazardLevel1 geologicalHazardLevel1
//                    gmSlopeData.setSlopeHazardLevel1(level);
//                    gmSlopeData.setGeologicalHazardLevel1(level1);
//                    break;
//                case 1: // L2（暴雨）→ slopeHazardLevel2
//                    gmSlopeData.setSlopeHazardLevel2(level);
//                    gmSlopeData.setGeologicalHazardLevel2(level1);
//                    break;
//                case 2: // L3（大暴雨）→ slopeHazardLevel3
//                    gmSlopeData.setSlopeHazardLevel3(level);
//                    gmSlopeData.setGeologicalHazardLevel3(level1);
//                    break;
//                case 3: // L4（特大暴雨）→ slopeHazardLevel4
//                    gmSlopeData.setSlopeHazardLevel4(level);
//                    gmSlopeData.setGeologicalHazardLevel4(level);
//                    break;
//                default:
//                    // 索引越界时的安全处理（如日志报警，可选）
//                    break;
//            }
//        }
//    }
    /**
     * 核心方法：从数据库参数（hazardParameters）动态读取常量，计算4种工况等级并写入实体
     * @param wi 边坡稳定性指数（动态传入）
     * @param y4 额外系数（业务传入）
     * @param gmSlopeData 需赋值的实体对象
     * @param hazardParameters 数据库参数对象（存储W_max、L_max、各L_j）
     */
    public static void calculateAndSetHazardLevels(
            double wi,
            double y4,
            GmSlopeData gmSlopeData,
            GmHazardParameters hazardParameters) {

        // ========== 1. 从hazardParameters读取参数（含空值保护） ==========
        // W_max：最大稳定性指数
        Double wMax = hazardParameters.getMaximumStabilityIndex();
        if (wMax == null) {
            wMax = 4.0; // 空值时 fallback 原默认值
        }

        // L_max：历史最大降雨均值
        Double lMax = hazardParameters.getHistoricalMaximumRainfall();
        if (lMax == null) {
            lMax = 178.94; // 空值时 fallback 原默认值（赣州）
        }

        // 4种降雨工况的L_j（大雨、暴雨、大暴雨、特大暴雨）
        Double ljRain1 = hazardParameters.getHeavyRain();    // 大雨
        Double ljRain2 = hazardParameters.getRainstorm();    // 暴雨
        Double ljRain3 = hazardParameters.getHeavyRainstorm();// 大暴雨
        Double ljRain4 = hazardParameters.getExtremelyHeavyRainstorm();// 特大暴雨

        // 组装L_j数组（空值时 fallback 原默认值）
        double[] ljArray = new double[4];
        ljArray[0] = Objects.nonNull(ljRain1) ? ljRain1 : 35;
        ljArray[1] = Objects.nonNull(ljRain2) ? ljRain2 : 75;
        ljArray[2] = Objects.nonNull(ljRain3) ? ljRain3 : 175;
        ljArray[3] = Objects.nonNull(ljRain4) ? ljRain4 : 250;


        // ========== 2. 遍历4种工况，计算并赋值实体 ==========
        for (int i = 0; i < ljArray.length; i++) {
            double lj = ljArray[i]; // 当前工况的雨量代表值

            // 公式计算：H_ij = (W_i / W_max) * ln(L_j / L_max + 2)
            double hij = (wi / wMax) * Math.log(lj / lMax + 2);
            double hij1 = hij * y4; // 地质灾害场景的指数（业务逻辑）

            // 判定危险等级
            String level = getRiskLevel(hij);     // 切坡场景等级
            String level1 = getRiskLevel1(hij1);  // 地质灾害场景等级（若规则不同需调整）

            // 根据工况索引，调用实体setter赋值对应字段
            switch (i) {
                case 0: // L1（大雨）→ slopeHazardLevel1、geologicalHazardLevel1
                    gmSlopeData.setSlopeHazardLevel1(level);
                    gmSlopeData.setGeologicalHazardLevel1(level1);
                    break;
                case 1: // L2（暴雨）→ slopeHazardLevel2、geologicalHazardLevel2
                    gmSlopeData.setSlopeHazardLevel2(level);
                    gmSlopeData.setGeologicalHazardLevel2(level1);
                    break;
                case 2: // L3（大暴雨）→ slopeHazardLevel3、geologicalHazardLevel3
                    gmSlopeData.setSlopeHazardLevel3(level);
                    gmSlopeData.setGeologicalHazardLevel3(level1);
                    break;
                case 3: // L4（特大暴雨）→ slopeHazardLevel4、geologicalHazardLevel4
                    gmSlopeData.setSlopeHazardLevel4(level);
                    gmSlopeData.setGeologicalHazardLevel4(level1);
                    break;
                default:
                    // 索引越界时的安全处理（如日志报警）
                    break;
            }
        }
    }

    /**
     * 核心方法：从数据库参数（hazardParameters）动态读取常量，计算4种工况等级并写入实体
     * @param wi 边坡稳定性指数（动态传入）
     * @param y4 额外系数（业务传入）
     * @param gmSlopeData 需赋值的实体对象
     * @param hazardParameters 数据库参数对象（存储W_max、L_max、各L_j）
     */
    public static void calculateAndSetHazardLevelsNew(
            double wi,
            double y4,
            GmSlopeData gmSlopeData,
            GmHazardParameters hazardParameters) {

        // ========== 1. 从hazardParameters读取参数（含空值保护） ==========
        // W_max：最大稳定性指数
        Double wMax = hazardParameters.getMaximumStabilityIndex();
        if (wMax == null) {
            wMax = 4.0; // 空值时 fallback 原默认值
        }

        // L_max：历史最大降雨均值
        Double lMax = hazardParameters.getHistoricalMaximumRainfall();
        if (lMax == null) {
            lMax = 178.94; // 空值时 fallback 原默认值（赣州）
        }

        // 4种降雨工况的L_j（大雨、暴雨、大暴雨、特大暴雨）
        Double ljRain1 = hazardParameters.getHeavyRain();    // 大雨
        Double ljRain2 = hazardParameters.getRainstorm();    // 暴雨
        Double ljRain3 = hazardParameters.getHeavyRainstorm();// 大暴雨
        Double ljRain4 = hazardParameters.getExtremelyHeavyRainstorm();// 特大暴雨

        // 组装L_j数组（空值时 fallback 原默认值）
        double[] ljArray = new double[4];
        ljArray[0] = Objects.nonNull(ljRain1) ? ljRain1 : 35;
        ljArray[1] = Objects.nonNull(ljRain2) ? ljRain2 : 75;
        ljArray[2] = Objects.nonNull(ljRain3) ? ljRain3 : 175;
        ljArray[3] = Objects.nonNull(ljRain4) ? ljRain4 : 250;


        // ========== 2. 遍历4种工况，计算并赋值实体 ==========
        for (int i = 0; i < ljArray.length; i++) {
            double lj = ljArray[i]; // 当前工况的雨量代表值

            // 公式计算：H_ij = (W_i / W_max) * ln(L_j / L_max + 2)
            double hij = (wi / wMax) * Math.log(lj / lMax + 2);
            double hij1 = hij * y4; // 地质灾害场景的指数（业务逻辑）

            // 判定危险等级
            String level = getRiskLevel(hij);     // 切坡场景等级
            String level1 = getRiskLevel1(hij1);  // 地质灾害场景等级（若规则不同需调整）

            // 根据工况索引，调用实体setter赋值对应字段
            switch (i) {
                case 0: // L1（大雨）→ slopeHazardLevel1、geologicalHazardLevel1
                    gmSlopeData.setSlopeHazardLevel1(level);
                    gmSlopeData.setGeologicalHazardLevel1(level1);
                    break;
                case 1: // L2（暴雨）→ slopeHazardLevel2、geologicalHazardLevel2
                    gmSlopeData.setSlopeHazardLevel2(level);
                    gmSlopeData.setGeologicalHazardLevel2(level1);
                    break;
                case 2: // L3（大暴雨）→ slopeHazardLevel3、geologicalHazardLevel3
                    gmSlopeData.setSlopeHazardLevel3(level);
                    gmSlopeData.setGeologicalHazardLevel3(level1);
                    break;
                case 3: // L4（特大暴雨）→ slopeHazardLevel4、geologicalHazardLevel4
                    gmSlopeData.setSlopeHazardLevel4(level);
                    gmSlopeData.setGeologicalHazardLevel4(level1);
                    break;
                default:
                    // 索引越界时的安全处理（如日志报警）
                    break;
            }
        }
    }
    /**
     * 危险等级判定逻辑：根据危险性指数 Hij 判定等级
     * @param hij 危险性指数
     * @return 危险等级字符串（极高危险/高危险/中危险/低危险）
     */
    private static String getRiskLevel(double hij) {
        if (hij >= 0.85) return "极高危险";
        else if (hij >= 0.75) return "高危险";
        else if (hij >= 0.65) return "中危险";
        else return "低危险";
    }
    /**
     * 危险等级判定逻辑：根据危险性指数 Hij 判定等级
     * @param hij 危险性指数
     * @return 危险等级字符串（极高危险/高危险/中危险/低危险）
     */
    private static String getRiskLevel1(double hij) {
        if (hij >= 2.5) return "极高风险";
        else if (hij >= 2.0) return "高风险";
        else if (hij >= 1.5) return "中风险";
        else return "低风险";
    }




    private static Double getFractureDevelopmentValue(RockSlopeStableSetting setting, String fractureDevelopmentDegree) {
        if (fractureDevelopmentDegree == null) {
            double sum = setting.getFractureDevelopment1() + setting.getFractureDevelopment2();
            return sum/2.0;
        }
        switch (fractureDevelopmentDegree) {
            case "A":
                return setting.getFractureDevelopment1();
            case "B":
                return setting.getFractureDevelopment2();
            default:
                //获取平均值计算
                double sum = setting.getFractureDevelopment1() + setting.getFractureDevelopment2();
                return sum/2.0;
        }
    }
    private static Double getFractureDevelopmentValue(SoilRockSlopeSetting setting, String fractureDevelopmentDegree) {
        if (fractureDevelopmentDegree == null) {
            double sum = setting.getUnderRockFracture1() + setting.getUnderRockFracture2();
            return sum/2.0;
        }
        switch (fractureDevelopmentDegree) {
            case "A":
                return setting.getUnderRockFracture1();
            case "B":
                return setting.getUnderRockFracture2();
            default:
                //获取平均值计算
                double sum = setting.getUnderRockFracture1() + setting.getUnderRockFracture2();
                return sum/2.0;
        }
    }
    private static Double getRockCharacteristicsValue(RockSlopeStableSetting setting, String rockCharacteristics) {
        if (rockCharacteristics == null) {
            double sum = setting.getRockCharacteristics1() + setting.getRockCharacteristics2();
            return sum/2.0;
        }

        switch (rockCharacteristics) {
            case "B":
                return setting.getRockCharacteristics1();
            case "A":
                return setting.getRockCharacteristics2();
            default:
                //获取平均值计算
                double sum = setting.getRockCharacteristics1() + setting.getRockCharacteristics2();
                return sum/2.0;
        }
    }
    private static Double getRockCharacteristicsValue(SoilRockSlopeSetting setting, String rockCharacteristics) {
        if (rockCharacteristics == null) {
            double sum = setting.getUnderCharacteristics1() + setting.getUnderCharacteristics2();
            return sum/2.0;
        }

        switch (rockCharacteristics) {
            case "B":
                return setting.getUnderCharacteristics1();
            case "A":
                return setting.getUnderCharacteristics2();
            default:
                //获取平均值计算
                double sum = setting.getUnderCharacteristics1() + setting.getUnderCharacteristics2();
                return sum/2.0;
        }
    }

    /**
     * 根据切坡高度获取对应的值
     *
     * @param setting
     * @param cutSlopeHeight
     * @return
     */
    private static Double getCutSlopeHeightValue(SlopeStableSetting setting, String cutSlopeHeight) {
        if (cutSlopeHeight == null) {
            double sum = setting.getCutSlopeHeight1() + setting.getCutSlopeHeight2() + setting.getCutSlopeHeight3() + setting.getCutSlopeHeight4();
            return sum/4.0;
        }
        switch (cutSlopeHeight) {
            case "A":
                return setting.getCutSlopeHeight1();
            case "B":
                return setting.getCutSlopeHeight2();
            case "C":
                return setting.getCutSlopeHeight3();
            case "D":
                return setting.getCutSlopeHeight4();
            default:
                //获取平均值计算
                double sum = setting.getCutSlopeHeight1() + setting.getCutSlopeHeight2() + setting.getCutSlopeHeight3() + setting.getCutSlopeHeight4();
                return sum/4.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据切坡高度获取对应的值
     *
     * @param setting
     * @param cutSlopeHeight
     * @return
     */
    private static Double getCutSlopeHeightValue(RockSlopeStableSetting setting, String cutSlopeHeight) {
        if (cutSlopeHeight == null) {
            double sum = setting.getCutSlopeHeight1() + setting.getCutSlopeHeight2() + setting.getCutSlopeHeight3() + setting.getCutSlopeHeight4();
            return sum/4.0;
        }

        switch (cutSlopeHeight) {
            case "A":
                return setting.getCutSlopeHeight1();
            case "B":
                return setting.getCutSlopeHeight2();
            case "C":
                return setting.getCutSlopeHeight3();
            case "D":
                return setting.getCutSlopeHeight4();
            default:
                //获取平均值计算
                double sum = setting.getCutSlopeHeight1() + setting.getCutSlopeHeight2() + setting.getCutSlopeHeight3() + setting.getCutSlopeHeight4();
                return sum/4.0; // 默认值或抛出异常
        }
    }

    /**
     * 根据切坡高度获取对应的值
     *
     * @param setting
     * @param cutSlopeHeight
     * @return
     */
    private static Double getCutSlopeHeightValue(SoilRockSlopeSetting setting, String cutSlopeHeight) {
        if (cutSlopeHeight == null) {
            double sum = setting.getCutSlopeHeight1() + setting.getCutSlopeHeight2() + setting.getCutSlopeHeight3() + setting.getCutSlopeHeight4();
            return sum/4.0;
        }
        switch (cutSlopeHeight) {
            case "A":
                return setting.getCutSlopeHeight1();
            case "B":
                return setting.getCutSlopeHeight2();
            case "C":
                return setting.getCutSlopeHeight3();
            case "D":
                return setting.getCutSlopeHeight4();
            default:
                //获取平均值计算
                double sum = setting.getCutSlopeHeight1() + setting.getCutSlopeHeight2() + setting.getCutSlopeHeight3() + setting.getCutSlopeHeight4();
                return sum/4.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据切坡坡度获取对应的值
     *
     * @param setting
     * @param cutSlopeGradient
     * @return
     */
    private static Double getCutSlopeGradientValue(SlopeStableSetting setting, String cutSlopeGradient) {
        if (cutSlopeGradient == null) {
            double sum = setting.getCutSlopeGradient1() + setting.getCutSlopeGradient2() + setting.getCutSlopeGradient3() + setting.getCutSlopeGradient4();
            return sum/4.0;
        }
        switch (cutSlopeGradient) {
            case "A":
                return setting.getCutSlopeGradient1();
            case "B":
                return setting.getCutSlopeGradient2();
            case "C":
                return setting.getCutSlopeGradient3();
            case "D":
                return setting.getCutSlopeGradient4();
            default:
                //获取平均值计算
                double sum = setting.getCutSlopeGradient1() + setting.getCutSlopeGradient2() + setting.getCutSlopeGradient3() + setting.getCutSlopeGradient4();
                return sum/4.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据切坡坡度获取对应的值
     *
     * @param setting
     * @param cutSlopeGradient
     * @return
     */
    private static Double getCutSlopeGradientValue(RockSlopeStableSetting setting, String cutSlopeGradient) {
        if (cutSlopeGradient == null) {
            double sum = setting.getCutSlopeGradient1() + setting.getCutSlopeGradient2() + setting.getCutSlopeGradient3() + setting.getCutSlopeGradient4();
            return sum/4.0;
        }
        switch (cutSlopeGradient) {
            case "A":
                return setting.getCutSlopeGradient1();
            case "B":
                return setting.getCutSlopeGradient2();
            case "C":
                return setting.getCutSlopeGradient3();
            case "D":
                return setting.getCutSlopeGradient4();
            default:
                //获取平均值计算
                double sum = setting.getCutSlopeGradient1() + setting.getCutSlopeGradient2() + setting.getCutSlopeGradient3() + setting.getCutSlopeGradient4();
                return sum/4.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据切坡坡度获取对应的值
     *
     * @param setting
     * @param cutSlopeGradient
     * @return
     */
    private static Double getCutSlopeGradientValue(SoilRockSlopeSetting setting, String cutSlopeGradient) {
        if (cutSlopeGradient == null) {
            double sum = setting.getCutSlopeGradient1() + setting.getCutSlopeGradient2() + setting.getCutSlopeGradient3() + setting.getCutSlopeGradient4();
            return sum/4.0;
        }
        switch (cutSlopeGradient) {
            case "A":
                return setting.getCutSlopeGradient1();
            case "B":
                return setting.getCutSlopeGradient2();
            case "C":
                return setting.getCutSlopeGradient3();
            case "D":
                return setting.getCutSlopeGradient4();
            default:
                //获取平均值计算
                double sum = setting.getCutSlopeGradient1() + setting.getCutSlopeGradient2() + setting.getCutSlopeGradient3() + setting.getCutSlopeGradient4();
                return sum/4.0; // 默认值或抛出异常
        }
    }

    /**
     * 计算岩组类型的 Y 值
     *
     * @param setting
     * @param rockType
     * @return
     */
    private static Double calculateRockY(SlopeStableSetting setting, String rockType) {
        if (rockType == null) {
            double sum = setting.getRockType1() + setting.getRockType2() +
                    setting.getRockType3() + setting.getRockType4() +
                    setting.getRockType5() + setting.getRockType6() +
                    setting.getRockType7() + setting.getRockType8() +
                    setting.getRockType9() + setting.getRockType10() +
                    setting.getRockType11() + setting.getRockType12() +
                    setting.getRockType13();
            return sum/13.0;
        }

        switch (rockType) {
            case "Y1":
                return setting.getRockType1();
            case "Y2":
                return setting.getRockType2();
            case "B3":
                return setting.getRockType3();
            case "B2":
                return setting.getRockType4();
            case "B1":
                return setting.getRockType5();
            case "S3":
                return setting.getRockType6();
            case "S4":
                return setting.getRockType7();
            case "S1":
                return setting.getRockType8();
            case "S2":
                return setting.getRockType9();
            case "S5":
                return setting.getRockType10();
            case "T3":
                return setting.getRockType11();
            case "T2":
                return setting.getRockType12();
            case "T1":
                return setting.getRockType13();
            default:
                //获取平均值计算
                double sum = setting.getRockType1() + setting.getRockType2() +
                        setting.getRockType3() + setting.getRockType4() +
                        setting.getRockType5() + setting.getRockType6() +
                        setting.getRockType7() + setting.getRockType8() +
                        setting.getRockType9() + setting.getRockType10() +
                        setting.getRockType11() + setting.getRockType12() +
                        setting.getRockType13();
                return sum/13.0; // 默认值或抛出异常
        }
    }
    /**
     * 计算岩组类型的 Y 值
     *
     * @param setting
     * @param rockType
     * @return
     */
    private static Double calculateRockY(SoilRockSlopeSetting setting, String rockType) {
        if (rockType == null) {
            double sum = setting.getRockType1() + setting.getRockType2() +
                    setting.getRockType3() + setting.getRockType4() +
                    setting.getRockType5() + setting.getRockType6() +
                    setting.getRockType7() + setting.getRockType8() +
                    setting.getRockType9() + setting.getRockType10() +
                    setting.getRockType11() + setting.getRockType12() +
                    setting.getRockType13();
            return sum/13.0;
        }
        switch (rockType) {
            case "Y1":
                return setting.getRockType1();
            case "Y2":
                return setting.getRockType2();
            case "B3":
                return setting.getRockType3();
            case "B2":
                return setting.getRockType4();
            case "B1":
                return setting.getRockType5();
            case "S3":
                return setting.getRockType6();
            case "S4":
                return setting.getRockType7();
            case "S1":
                return setting.getRockType8();
            case "S2":
                return setting.getRockType9();
            case "S5":
                return setting.getRockType10();
            case "T3":
                return setting.getRockType11();
            case "T2":
                return setting.getRockType12();
            case "T1":
                return setting.getRockType13();
            default:
                //获取平均值计算
                double sum = setting.getRockType1() + setting.getRockType2() +
                        setting.getRockType3() + setting.getRockType4() +
                        setting.getRockType5() + setting.getRockType6() +
                        setting.getRockType7() + setting.getRockType8() +
                        setting.getRockType9() + setting.getRockType10() +
                        setting.getRockType11() + setting.getRockType12() +
                        setting.getRockType13();
                return sum/13.0; // 默认值或抛出异常
        }
    }
    /**
     * 计算岩组类型的 Y 值
     *
     * @param setting
     * @param rockType
     * @return
     */
    private static Double calculateRockY(RockSlopeStableSetting setting, String rockType) {
        if (rockType == null) {
            double sum = setting.getRockType1() + setting.getRockType2() +
                    setting.getRockType3() + setting.getRockType4() +
                    setting.getRockType5() + setting.getRockType6() +
                    setting.getRockType7() + setting.getRockType8() +
                    setting.getRockType9() + setting.getRockType10() +
                    setting.getRockType11() + setting.getRockType12() +
                    setting.getRockType13();
            return sum/13.0;
        }
        switch (rockType) {
            case "Y1":
                return setting.getRockType1();
            case "Y2":
                return setting.getRockType2();
            case "B3":
                return setting.getRockType3();
            case "B2":
                return setting.getRockType4();
            case "B1":
                return setting.getRockType5();
            case "S3":
                return setting.getRockType6();
            case "S4":
                return setting.getRockType7();
            case "S1":
                return setting.getRockType8();
            case "S2":
                return setting.getRockType9();
            case "S5":
                return setting.getRockType10();
            case "T3":
                return setting.getRockType11();
            case "T2":
                return setting.getRockType12();
            case "T1":
                return setting.getRockType13();
            default:
                //获取平均值计算
                double sum = setting.getRockType1() + setting.getRockType2() +
                        setting.getRockType3() + setting.getRockType4() +
                        setting.getRockType5() + setting.getRockType6() +
                        setting.getRockType7() + setting.getRockType8() +
                        setting.getRockType9() + setting.getRockType10() +
                        setting.getRockType11() + setting.getRockType12() +
                        setting.getRockType13();
                return sum/13.0; // 默认值或抛出异常
        }
    }

    /**
     * 根据切坡坡形获取对应的值
     *
     * @param setting
     * @param cutSlopeShape
     * @return
     */
    private static Double getCutSlopeShapeValue(SlopeStableSetting setting, String cutSlopeShape) {
        if (cutSlopeShape == null) {
            double sum = setting.getCutSlopeShape1() + setting.getCutSlopeShape2() + setting.getCutSlopeShape3() + setting.getCutSlopeShape4();
            return sum/4.0;
        }
        switch (cutSlopeShape) {
            case "A":
                return setting.getCutSlopeShape1();
            case "B":
                return setting.getCutSlopeShape2();
            case "C":
                return setting.getCutSlopeShape3();
            case "D":
                return setting.getCutSlopeShape4();
            default:
                //获取平均值计算
                double sum = setting.getCutSlopeShape1() + setting.getCutSlopeShape2() + setting.getCutSlopeShape3() + setting.getCutSlopeShape4();
                return sum/4.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据切坡坡形获取对应的值
     *
     * @param setting
     * @param cutSlopeShape
     * @return
     */
    private static Double getCutSlopeShapeValue(SoilRockSlopeSetting setting, String cutSlopeShape) {
        if (cutSlopeShape == null) {
            double sum = setting.getCutSlopeShape1() + setting.getCutSlopeShape2() + setting.getCutSlopeShape3() + setting.getCutSlopeShape4();
            return sum/4.0;
        }
        switch (cutSlopeShape) {
            case "A":
                return setting.getCutSlopeShape1();
            case "B":
                return setting.getCutSlopeShape2();
            case "C":
                return setting.getCutSlopeShape3();
            case "D":
                return setting.getCutSlopeShape4();
            default:
                //获取平均值计算
                double sum = setting.getCutSlopeShape1() + setting.getCutSlopeShape2() + setting.getCutSlopeShape3() + setting.getCutSlopeShape4();
                return sum/4.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据切坡坡形获取对应的值
     *
     * @param setting
     * @param cutSlopeShape
     * @return
     */
    private static Double getCutSlopeShapeValue(RockSlopeStableSetting setting, String cutSlopeShape) {
        if (cutSlopeShape == null) {
            double sum = setting.getCutSlopeShape1() + setting.getCutSlopeShape2() + setting.getCutSlopeShape3() + setting.getCutSlopeShape4();
            return sum/4.0;
        }
        switch (cutSlopeShape) {
            case "A":
                return setting.getCutSlopeShape1();
            case "B":
                return setting.getCutSlopeShape2();
            case "C":
                return setting.getCutSlopeShape3();
            case "D":
                return setting.getCutSlopeShape4();
            default:
                //获取平均值计算
                double sum = setting.getCutSlopeShape1() + setting.getCutSlopeShape2() + setting.getCutSlopeShape3() + setting.getCutSlopeShape4();
                return sum/4.0; // 默认值或抛出异常
        }
    }

    /**
     * 根据自然斜坡坡度获取对应的值
     *
     * @param setting
     * @param naturalSlopeGradient
     * @return
     */
    private static Double getNaturalSlopeGradientValue(SlopeStableSetting setting, String naturalSlopeGradient) {
        if (naturalSlopeGradient == null) {
            double sum = setting.getNaturalSlopeGradient1() + setting.getNaturalSlopeGradient2() + setting.getNaturalSlopeGradient3();
            return sum/3.0;
        }
        switch (naturalSlopeGradient) {
            case "A":
                return setting.getNaturalSlopeGradient1();
            case "B":
                return setting.getNaturalSlopeGradient2();
            case "C":
                return setting.getNaturalSlopeGradient3();
            default:
                //获取平均值计算
                double sum = setting.getNaturalSlopeGradient1() + setting.getNaturalSlopeGradient2() + setting.getNaturalSlopeGradient3();
                return sum/3.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据自然斜坡坡度获取对应的值
     *
     * @param setting
     * @param naturalSlopeGradient
     * @return
     */
    private static Double getNaturalSlopeGradientValue(SoilRockSlopeSetting setting, String naturalSlopeGradient) {
        if (naturalSlopeGradient == null) {
            double sum = setting.getNaturalSlopeGradient1() + setting.getNaturalSlopeGradient2() + setting.getNaturalSlopeGradient3();
            return sum/3.0;
        }
        switch (naturalSlopeGradient) {
            case "A":
                return setting.getNaturalSlopeGradient1();
            case "B":
                return setting.getNaturalSlopeGradient2();
            case "C":
                return setting.getNaturalSlopeGradient3();
            default:
                //获取平均值计算
                double sum = setting.getNaturalSlopeGradient1() + setting.getNaturalSlopeGradient2() + setting.getNaturalSlopeGradient3();
                return sum/3.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据自然斜坡坡度获取对应的值
     *
     * @param setting
     * @param naturalSlopeGradient
     * @return
     */
    private static Double getNaturalSlopeGradientValue(RockSlopeStableSetting setting, String naturalSlopeGradient) {
        if (naturalSlopeGradient == null) {
            double sum = setting.getNaturalSlopeGradient1() + setting.getNaturalSlopeGradient2() + setting.getNaturalSlopeGradient3();
            return sum/3.0;
        }
        switch (naturalSlopeGradient) {
            case "A":
                return setting.getNaturalSlopeGradient1();
            case "B":
                return setting.getNaturalSlopeGradient2();
            case "C":
                return setting.getNaturalSlopeGradient3();
            default:
                //获取平均值计算
                double sum = setting.getNaturalSlopeGradient1() + setting.getNaturalSlopeGradient2() + setting.getNaturalSlopeGradient3();
                return sum/3.0; // 默认值或抛出异常
        }
    }

    /**
     * 根据土层松散程度获取对应的值
     *
     * @param setting
     * @param soilLooseness
     * @return
     */
    private static Double getSoilLoosenessValue(SlopeStableSetting setting, String soilLooseness) {


        if (soilLooseness == null) {
            double sum = setting.getSoilLooseness1() + setting.getSoilLooseness2();
            return sum/2.0;
        }
        switch (soilLooseness) {
            case "B":
                return setting.getSoilLooseness1();
            case "A":
                return setting.getSoilLooseness2();
            default:
                //获取平均值计算
                double sum = setting.getSoilLooseness1() + setting.getSoilLooseness2();
                return sum/2.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据土层松散程度获取对应的值
     *
     * @param setting
     * @param soilLooseness
     * @return
     */
    private static Double getSoilLoosenessValue(SoilRockSlopeSetting setting, String soilLooseness) {
        if (soilLooseness == null) {
            double sum = setting.getUpperSoilLooseness1() + setting.getUpperSoilLooseness2();
            return sum/2.0;
        }
        switch (soilLooseness) {
            case "B":
                return setting.getUpperSoilLooseness1();
            case "A":
                return setting.getUpperSoilLooseness2();
            default:
                //获取平均值计算
                double sum = setting.getUpperSoilLooseness1() + setting.getUpperSoilLooseness2();
                return sum/2.0; // 默认值或抛出异常
        }
    }

    /**
     * 根据土体类型获取对应的值
     *
     * @param setting
     * @param overlyingSoilType
     * @return
     */
    private static Double getOverlyingSoilTypeValue(SlopeStableSetting setting, String overlyingSoilType) {
        if (overlyingSoilType == null) {
            double sum = setting.getOverlyingSoilType1() + setting.getOverlyingSoilType2() + setting.getOverlyingSoilType3();
            return sum/3.0;
        }
        switch (overlyingSoilType) {
            case "A":
                return setting.getOverlyingSoilType1();
            case "B":
                return setting.getOverlyingSoilType2();
            case "C":
                return setting.getOverlyingSoilType3();
            default:
                //获取平均值计算
                double sum = setting.getOverlyingSoilType1() + setting.getOverlyingSoilType2() + setting.getOverlyingSoilType3();
                return sum/3.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据土体类型获取对应的值
     *
     * @param setting
     * @param overlyingSoilType
     * @return
     */
    private static Double getOverlyingSoilTypeValue(SoilRockSlopeSetting setting, String overlyingSoilType) {
        if (overlyingSoilType == null) {
            double sum = setting.getUpperSoilType1() + setting.getUpperSoilType2() + setting.getUpperSoilType3();
            return sum/3.0;
        }
        switch (overlyingSoilType) {
            case "A":
                return setting.getUpperSoilType1();
            case "B":
                return setting.getUpperSoilType2();
            case "C":
                return setting.getUpperSoilType3();
            default:
                //获取平均值计算
                double sum = setting.getUpperSoilType1() + setting.getUpperSoilType2() + setting.getUpperSoilType3();
                return sum/3.0; // 默认值或抛出异常
        }
    }

    /**
     * 根据植被覆盖率获取对应的值
     *
     * @param setting
     * @param vegetationCoverage
     * @return
     */
    private static Double getVegetationCoverageValue(SlopeStableSetting setting, String vegetationCoverage) {
        if (vegetationCoverage == null) {
            double sum = setting.getVegetationCoverage1() + setting.getVegetationCoverage2() + setting.getVegetationCoverage3();
            return sum/3.0;
        }
        switch (vegetationCoverage) {
            case "A":
                return setting.getVegetationCoverage1();
            case "B":
                return setting.getVegetationCoverage2();
            case "C":
                return setting.getVegetationCoverage3();
            default:
                //获取平均值计算
                double sum = setting.getVegetationCoverage1() + setting.getVegetationCoverage2() + setting.getVegetationCoverage3();
                return sum/3.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据植被覆盖率获取对应的值
     *
     * @param setting
     * @param vegetationCoverage
     * @return
     */
    private static Double getVegetationCoverageValue(SoilRockSlopeSetting setting, String vegetationCoverage) {
        if (vegetationCoverage == null) {
            double sum = setting.getVegetationCoverage1() + setting.getVegetationCoverage2() + setting.getVegetationCoverage3();
            return sum/3.0;
        }
        switch (vegetationCoverage) {
            case "A":
                return setting.getVegetationCoverage1();
            case "B":
                return setting.getVegetationCoverage2();
            case "C":
                return setting.getVegetationCoverage3();
            default:
                //获取平均值计算
                double sum = setting.getVegetationCoverage1() + setting.getVegetationCoverage2() + setting.getVegetationCoverage3();
                return sum/3.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据植被覆盖率获取对应的值
     *
     * @param setting
     * @param vegetationCoverage
     * @return
     */
    private static Double getVegetationCoverageValue(RockSlopeStableSetting setting, String vegetationCoverage) {
        if (vegetationCoverage == null) {
            double sum = setting.getVegetationCoverage1() + setting.getVegetationCoverage2() + setting.getVegetationCoverage3();
            return sum/3.0;
        }
        switch (vegetationCoverage) {
            case "A":
                return setting.getVegetationCoverage1();
            case "B":
                return setting.getVegetationCoverage2();
            case "C":
                return setting.getVegetationCoverage3();
            default:
                //获取平均值计算
                double sum = setting.getVegetationCoverage1() + setting.getVegetationCoverage2() + setting.getVegetationCoverage3();
                return sum/3.0; // 默认值或抛出异常
        }
    }

    /**
     * 根据已有治理措施获取对应的值
     *
     * @param setting
     * @param governanceMeasures
     * @return
     */
    private static Double getGovernanceMeasuresValue(SlopeStableSetting setting, String governanceMeasures) {
        if (governanceMeasures == null) {
            double sum = setting.getGovernanceMeasures1() + setting.getGovernanceMeasures2() + setting.getGovernanceMeasures3() + setting.getGovernanceMeasures4();
            return sum/4.0;
        }

        switch (governanceMeasures) {
            case "A":
                return setting.getGovernanceMeasures1();
            case "B":
                return setting.getGovernanceMeasures2();
            case "C":
                return setting.getGovernanceMeasures3();
            case "D":
                return setting.getGovernanceMeasures4();
            default:
                //获取平均值计算
                double sum = setting.getGovernanceMeasures1() + setting.getGovernanceMeasures2() + setting.getGovernanceMeasures3() + setting.getGovernanceMeasures4();
                return sum/4.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据已有治理措施获取对应的值
     *
     * @param setting
     * @param governanceMeasures
     * @return
     */
    private static Double getGovernanceMeasuresValue(SoilRockSlopeSetting setting, String governanceMeasures) {
        if (governanceMeasures == null) {
            double sum = setting.getGovernanceMeasures1() + setting.getGovernanceMeasures2() +
                    setting.getGovernanceMeasures3() + setting.getGovernanceMeasures4();
            return sum/4.0;
        }
        switch (governanceMeasures) {
            case "A":
                return setting.getGovernanceMeasures1();
            case "B":
                return setting.getGovernanceMeasures2();
            case "C":
                return setting.getGovernanceMeasures3();
            case "D":
                return setting.getGovernanceMeasures4();
            default:
                //获取平均值计算
                double sum = setting.getGovernanceMeasures1() + setting.getGovernanceMeasures2() +
                        setting.getGovernanceMeasures3() + setting.getGovernanceMeasures4();
                return sum/4.0; // 默认值或抛出异常
        }
    }
    /**
     * 根据已有治理措施获取对应的值
     *
     * @param setting
     * @param governanceMeasures
     * @return
     */
    private static Double getGovernanceMeasuresValue(RockSlopeStableSetting setting, String governanceMeasures) {
        if (governanceMeasures == null) {
            double sum = setting.getGovernanceMeasures1() + setting.getGovernanceMeasures2() +
                    setting.getGovernanceMeasures3() + setting.getGovernanceMeasures4();
            return sum/4.0;
        }
        switch (governanceMeasures) {
            case "A":
                return setting.getGovernanceMeasures1();
            case "B":
                return setting.getGovernanceMeasures2();
            case "C":
                return setting.getGovernanceMeasures3();
            case "D":
                return setting.getGovernanceMeasures4();
            default:
                //获取平均值计算
                double sum = setting.getGovernanceMeasures1() + setting.getGovernanceMeasures2() +
                        setting.getGovernanceMeasures3() + setting.getGovernanceMeasures4();
                return sum/4.0; // 默认值或抛出异常
        }
    }


    private static Double getThreatHouseValue(SlopeRiskEvaluationSetting riskSetting, String threatHouse) {
        if (threatHouse == null){
            double sum = riskSetting.getThreatHouse1() + riskSetting.getThreatHouse2()+
                    riskSetting.getThreatHouse3() + riskSetting.getThreatHouse4();
            return sum/4.0;
        }

        switch (threatHouse) {
            case "A":
                return riskSetting.getThreatHouse1();
            case "B":
                return riskSetting.getThreatHouse2();
            case "C":
                return riskSetting.getThreatHouse3();
            case "D":
                return riskSetting.getThreatHouse4();
            default:
                //获取平均值计算
                double sum = riskSetting.getThreatHouse1() + riskSetting.getThreatHouse2()+
                        riskSetting.getThreatHouse3() + riskSetting.getThreatHouse4();
                return sum/4.0;
        }
    }

//    private static Double getThreatPopulationValue(SlopeRiskEvaluationSetting riskSetting, String threatPopulation) {
//        if (threatPopulation == null){
//            double sum = riskSetting.getThreatPopulation1() + riskSetting.getThreatPopulation2()+
//                    riskSetting.getThreatPopulation3() + riskSetting.getThreatPopulation4();
//            return sum/4.0;
//        }
//
//        //根据人数进行判断
//        int B = Integer.parseInt(threatPopulation);
//
//        if (B < 3) {
//            return riskSetting.getThreatPopulation1();
//        } else if (B < 10) {
//            return riskSetting.getThreatPopulation2();
//        } else if (B < 30) {
//            return riskSetting.getThreatPopulation3();
//        } else if (B >= 30) {
//            return riskSetting.getThreatPopulation4();
//        }else {
//            //获取平均值计算
//            double sum = riskSetting.getThreatPopulation1() + riskSetting.getThreatPopulation2() +
//                    riskSetting.getThreatPopulation3() + riskSetting.getThreatPopulation4();
//            return sum / 4.0;
//        }
//    }
private static Double getThreatPopulationValue(SlopeRiskEvaluationSetting riskSetting, String threatPopulation) {
    if (threatPopulation == null || threatPopulation.trim().isEmpty()) {
        double sum = riskSetting.getThreatPopulation1() + riskSetting.getThreatPopulation2() +
                riskSetting.getThreatPopulation3() + riskSetting.getThreatPopulation4();
        return sum / 4.0;
    }

    try {
        // 根据人数进行判断
        int B = Integer.parseInt(threatPopulation.trim());

        if (B < 3) {
            return riskSetting.getThreatPopulation1();
        } else if (B < 10) {
            return riskSetting.getThreatPopulation2();
        } else if (B < 30) {
            return riskSetting.getThreatPopulation3();
        } else { // B >= 30
            return riskSetting.getThreatPopulation4();
        }
    } catch (NumberFormatException e) {
        // 当输入不是有效数字时，返回默认值或计算平均值
        double sum = riskSetting.getThreatPopulation1() + riskSetting.getThreatPopulation2() +
                riskSetting.getThreatPopulation3() + riskSetting.getThreatPopulation4();
        return sum / 4.0;
    }
}




    private static Double getCutSlopeWidthValue(SlopeRiskEvaluationSetting riskSetting, String cutSlopeWidth) {
        if (cutSlopeWidth == null){
            double sum = riskSetting.getCutSlopeWidth1() + riskSetting.getCutSlopeWidth2()+
                    riskSetting.getCutSlopeWidth3() + riskSetting.getCutSlopeWidth4();
            return sum/4.0;
        }
        switch (cutSlopeWidth) {
            case "A":
                return riskSetting.getCutSlopeWidth1();
            case "B":
                return riskSetting.getCutSlopeWidth2();
            case "C":
                return riskSetting.getCutSlopeWidth3();
            case "D":
                return riskSetting.getCutSlopeWidth4();
            default:
                //获取平均值计算
                double sum = riskSetting.getCutSlopeWidth1() + riskSetting.getCutSlopeWidth2()+
                        riskSetting.getCutSlopeWidth3() + riskSetting.getCutSlopeWidth4();
                return sum/4.0;
        }
    }

    private static Double getCutSlopeTimeValue(SlopeRiskEvaluationSetting riskSetting, String cutSlopeTime) {
        if (cutSlopeTime == null){
            double sum = riskSetting.getCutSlopeTime1() + riskSetting.getCutSlopeTime2();
            return sum/2.0;
        }
        switch (cutSlopeTime) {
            case "A":
                return riskSetting.getCutSlopeTime1();
            case "B":
                return riskSetting.getCutSlopeTime2();
            default:
                //获取平均值计算
                double sum = riskSetting.getCutSlopeTime1() + riskSetting.getCutSlopeTime2();
                return sum/2.0;
        }
    }

    private static Double getWallDistanceValue(SlopeRiskEvaluationSetting riskSetting, String slopeWallDistance) {
        if (slopeWallDistance == null){
            double sum = riskSetting.getSlopeWallDistance1() + riskSetting.getSlopeWallDistance2()+
                    riskSetting.getSlopeWallDistance3() + riskSetting.getSlopeWallDistance4();
            return sum/2.0;
        }
        switch (slopeWallDistance) {
            case "A":
                return riskSetting.getSlopeWallDistance1();
            case "B":
                return riskSetting.getSlopeWallDistance2();
            case "C":
                return riskSetting.getSlopeWallDistance3();
            case "D":
                return riskSetting.getSlopeWallDistance4();
            default:
                //获取平均值计算
                double sum = riskSetting.getSlopeWallDistance1() + riskSetting.getSlopeWallDistance2()+
                        riskSetting.getSlopeWallDistance3() + riskSetting.getSlopeWallDistance4();
                return sum/4.0;
        }
    }


//    private static final double PI = 3.1415926535897932384626;
//    private static final double AXIS = 6378245.0;
//    private static final double OFFSET = 0.00669342162296594323; // (a^2 - b^2)/a^2
//
//    /**
//     * 将GCJ-02坐标转换为WGS84坐标
//     * @param gcjLat GCJ-02纬度
//     * @param gcjLng GCJ-02经度
//     * @return 转换后的WGS84坐标，double[0]为纬度，double[1]为经度
//     */
//    public static double[] gcj02ToWgs84(double gcjLat, double gcjLng) {
//        // 如果坐标不在中国区域，直接返回原坐标
//        if (!isInChina(gcjLat, gcjLng)) {
//            return new double[]{gcjLat, gcjLng};
//        }
//
//        // 计算偏移量
//        double[] delta = calculateDelta(gcjLat, gcjLng);
//        // 用GCJ-02坐标减去偏移量得到WGS84坐标
//        return new double[]{gcjLat - delta[0], gcjLng - delta[1]};
//    }
//
//    /**
//     * 计算GCJ-02相对于WGS84的偏移量
//     */
//    private static double[] calculateDelta(double lat, double lon) {
//        double dLat = calculateLat(lon - 105.0, lat - 35.0);
//        double dLon = calculateLon(lon - 105.0, lat - 35.0);
//
//        double radLat = lat / 180.0 * PI;
//        double magic = Math.sin(radLat);
//        magic = 1 - OFFSET * magic * magic;
//        double sqrtMagic = Math.sqrt(magic);
//
//        dLat = (dLat * 180.0) / ((AXIS * (1 - OFFSET)) / (magic * sqrtMagic) * PI);
//        dLon = (dLon * 180.0) / (AXIS / sqrtMagic * Math.cos(radLat) * PI);
//
//        return new double[]{dLat, dLon};
//    }
//
//    private static double calculateLat(double x, double y) {
//        double result = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
//        result += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
//        result += (20.0 * Math.sin(y * PI) + 40.0 * Math.sin(y / 3.0 * PI)) * 2.0 / 3.0;
//        result += (160.0 * Math.sin(y / 12.0 * PI) + 320 * Math.sin(y * PI / 30.0)) * 2.0 / 3.0;
//        return result;
//    }
//
//    private static double calculateLon(double x, double y) {
//        double result = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
//        result += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
//        result += (20.0 * Math.sin(x * PI) + 40.0 * Math.sin(x / 3.0 * PI)) * 2.0 / 3.0;
//        result += (150.0 * Math.sin(x / 12.0 * PI) + 300.0 * Math.sin(x / 30.0 * PI)) * 2.0 / 3.0;
//        return result;
//    }
//
//    /**
//     * 判断坐标是否在中国境内（粗略判断）
//     */
//    private static boolean isInChina(double lat, double lon) {
//        if (lon < 72.004 || lon > 137.8347) {
//            return false;
//        }
//        if (lat < 0.8293 || lat > 55.8271) {
//            return false;
//        }
//        return true;
//    }

    private static final double PI = 3.14159265358979324;
    private static final double A = 6378245.0; // 卫星椭球坐标投影到平面地图坐标系的投影因子
    private static final double EE = 0.00669342162296594323; // 椭球的偏心率

    /**
     * 将GCJ坐标转换为WGS坐标
     * @param gcjLat GCJ纬度
     * @param gcjLon GCJ经度
     * @return 包含WGS纬度和经度的double数组，[纬度, 经度]
     */
    public static double[] transformGCJ2WGS(double gcjLat, double gcjLon) {
        double[] delta = delta(gcjLat, gcjLon);
        return new double[]{gcjLat - delta[0], gcjLon - delta[1]};
    }

    /**
     * 计算坐标偏差
     * @param lat 纬度
     * @param lon 经度
     * @return 包含纬度偏差和经度偏差的double数组，[纬度偏差, 经度偏差]
     */
    private static double[] delta(double lat, double lon) {
        double dLat = transformLat(lon - 105.0, lat - 35.0);
        double dLon = transformLon(lon - 105.0, lat - 35.0);
        double radLat = lat / 180.0 * PI;
        double magic = Math.sin(radLat);
        magic = 1 - EE * magic * magic;
        double sqrtMagic = Math.sqrt(magic);
        dLat = (dLat * 180.0) / ((A * (1 - EE)) / (magic * sqrtMagic) * PI);
        dLon = (dLon * 180.0) / (A / sqrtMagic * Math.cos(radLat) * PI);
        return new double[]{dLat, dLon};
    }

    /**
     * 计算纬度转换值
     * @param x x坐标
     * @param y y坐标
     * @return 转换后的纬度值
     */
    private static double transformLat(double x, double y) {
        double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(y * PI) + 40.0 * Math.sin(y / 3.0 * PI)) * 2.0 / 3.0;
        ret += (160.0 * Math.sin(y / 12.0 * PI) + 320 * Math.sin(y * PI / 30.0)) * 2.0 / 3.0;
        return ret;
    }

    /**
     * 计算经度转换值
     * @param x x坐标
     * @param y y坐标
     * @return 转换后的经度值
     */
    private static double transformLon(double x, double y) {
        double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(x * PI) + 40.0 * Math.sin(x / 3.0 * PI)) * 2.0 / 3.0;
        ret += (150.0 * Math.sin(x / 12.0 * PI) + 300.0 * Math.sin(x / 30.0 * PI)) * 2.0 / 3.0;
        return ret;
    }

    public static double modifyY(double y, GmIndexAdjustment indexAdjustment, GmSlopeData gmSlopeData) {
        String vegetationCoverage = gmSlopeData.getVegetationCoverage();
        String measure = gmSlopeData.getGovernanceMeasures();
        switch (vegetationCoverage) {
            case "A":
                 y=y * indexAdjustment.getVegetationcoveragefactor1();
                 break;
            case "B":
                 y=y * indexAdjustment.getVegetationcoveragefactor2();
                 break;
            case "C":
                 y=y * indexAdjustment.getVegetationcoveragefactor3();
        }
//        System.out.println("y2 = " + y);
        // 处理治理措施调整（支持多个值，用逗号分隔）
        if (measure != null && !measure.isEmpty()) {
            String[] measures = measure.split(",");
            for (String m : measures) {
                switch (m.trim()) { // 去除可能的空格
                    case "A":
                        y = y * indexAdjustment.getGovernancemeasures1();
                        break;
                    case "B":
                        y = y * indexAdjustment.getGovernancemeasures2();
                        break;
                    case "C":
                        y = y * indexAdjustment.getGovernancemeasures3();
                        break;
                    case "D":
                        y = y * indexAdjustment.getGovernancemeasures4();
                        break;
                }
            }
        }

        return y;
    }
}
